package com.thoughtworks.impersonator.http.record.google;

import static com.thoughtworks.impersonator.http.IntegrationTestUtils.get;
import static org.junit.Assert.assertEquals;

import java.io.File;

import org.junit.Test;

import com.thoughtworks.impersonator.http.message.RequestIdentifier;
import com.thoughtworks.impersonator.http.record.Recorder;
import com.thoughtworks.impersonator.http.replay.Impersonator;
import com.thoughtworks.impersonator.http.test.FixedUidRequestIdentifier;

public class GoogleTest {

    private static final int RECORDER_PORT = 9930;
    private static final int IMPERSONATOR_PORT = RECORDER_PORT + 1;

    @Test
    public void testGoogle() throws Exception {
        File storageDir = new File("target/tmp");
        RequestIdentifier requestIdentifier = new FixedUidRequestIdentifier("google-test"); 

        Recorder recorder = new Recorder(RECORDER_PORT, "www.google.com.au", 80, storageDir, requestIdentifier);
        String expected = get("http://127.0.0.1:" + RECORDER_PORT + "/search?q=test");
        recorder.stop();

        Impersonator impersonator = new Impersonator(IMPERSONATOR_PORT, storageDir, requestIdentifier);
        String returned = get("http://127.0.0.1:" + IMPERSONATOR_PORT + "/search?q=test");
        impersonator.stop();

        assertEquals(returned, expected);
    }

}
